package com.dk.base.core.event;

import com.dk.base.core.service.DemoService;
import com.dk.shared.events.common.AbstractEventHandler;
import com.dk.shared.events.demo.DemoBusEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Slf4j
@Component
public class DemoBusEventHandler extends AbstractEventHandler<DemoBusEvent> {

    @Autowired
    private DemoService demoService;

    public DemoBusEventHandler() {
        super(true);
    }

    @Override
    protected void handleEvent(DemoBusEvent event) {
         Integer num  =  event.getNum();
        log.info("inset {}",num);
        try {
            Thread.sleep(5*1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        demoService.saveByEvent(num);
    }
}
